package com.dupt.web.controller.assemble;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dupt.common.annotation.Log;
import com.dupt.common.core.controller.BaseController;
import com.dupt.common.core.domain.AjaxResult;
import com.dupt.common.enums.BusinessType;
import com.dupt.system.domain.AssemblePlan;
import com.dupt.system.service.IAssemblePlanService;
import com.dupt.common.utils.poi.ExcelUtil;
import com.dupt.common.core.page.TableDataInfo;

/**
 * 组装计划Controller
 * 
 * @author zhuanyu.sun
 * @date 2025-07-10
 */
@RestController
@RequestMapping("/assemble/plan")
public class AssemblePlanController extends BaseController
{
    @Autowired
    private IAssemblePlanService assemblePlanService;

    /**
     * 查询组装计划列表
     */
    @PreAuthorize("@ss.hasPermi('assemble:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssemblePlan assemblePlan)
    {
        startPage();
        List<AssemblePlan> list = assemblePlanService.selectAssemblePlanList(assemblePlan);
        return getDataTable(list);
    }

    /**
     * 导出组装计划列表
     */
    @PreAuthorize("@ss.hasPermi('assemble:plan:export')")
    @Log(title = "组装计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssemblePlan assemblePlan)
    {
        List<AssemblePlan> list = assemblePlanService.selectAssemblePlanList(assemblePlan);
        ExcelUtil<AssemblePlan> util = new ExcelUtil<AssemblePlan>(AssemblePlan.class);
        util.exportExcel(response, list, "组装计划数据");
    }

    /**
     * 获取组装计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('assemble:plan:query')")
    @GetMapping(value = "/{assembleId}")
    public AjaxResult getInfo(@PathVariable("assembleId") String assembleId)
    {
        return success(assemblePlanService.selectAssemblePlanByAssembleId(assembleId));
    }

    /**
     * 新增组装计划
     */
    @PreAuthorize("@ss.hasPermi('assemble:plan:add')")
    @Log(title = "组装计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssemblePlan assemblePlan)
    {
        return toAjax(assemblePlanService.insertAssemblePlan(assemblePlan));
    }

    /**
     * 修改组装计划
     */
    @PreAuthorize("@ss.hasPermi('assemble:plan:edit')")
    @Log(title = "组装计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssemblePlan assemblePlan)
    {
        return toAjax(assemblePlanService.updateAssemblePlan(assemblePlan));
    }

    /**
     * 删除组装计划
     */
    @PreAuthorize("@ss.hasPermi('assemble:plan:remove')")
    @Log(title = "组装计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assembleIds}")
    public AjaxResult remove(@PathVariable String[] assembleIds)
    {
        return toAjax(assemblePlanService.deleteAssemblePlanByAssembleIds(assembleIds));
    }

    /**
     * 入库
     */
    @PreAuthorize("@ss.hasPermi('assemble:plan: inStorage')")
    @Log(title = "组装计划", businessType = BusinessType.UPDATE)
    @GetMapping("/inStorage")
    public AjaxResult inStorage(@RequestBody AssemblePlan assemblePlan)
    {
        return toAjax(assemblePlanService.inStorage(assemblePlan));
    }

    /**
     * 查询组装计划
     */
    @GetMapping("/planList")
    public List<AssemblePlan> planList()
    {
        return assemblePlanService.planList();
    }
}
